/*
 * SyncList.h
 *
 *  Created on: 2012-12-24
 *      Author: yangentao@gmail.com
 */

#pragma once;
#include "Vector.h"
#include "AutoLock.h"

using namespace std;

namespace yet {

template<typename T>
class SyncQueue: public ThreadLock {

public:
	SyncQueue() {
	}
	virtual ~SyncQueue() {
	}
public:
	void push_front(T val) {
		AutoLock al(this);
		vec.push_front(val);
	}
	void push_back(T val) {
		AutoLock al(this);
		vec.push_back(val);
	}
	T pop_front() {
		AutoLock al(this);
		T v = vec.first();
		vec.pop_front();
		return v;
	}
	T pop_back() {
		AutoLock al(this);
		T v = vec.last();
		vec.pop_back();
		return v;
	}
	T front() {
		AutoLock al(this);
		return vec.first();
	}
	T back() {
		AutoLock al(this);
		return vec.last();
	}
	size_t size() {
		AutoLock al(this);
		return vec.size();
	}
	bool empty() {
		return size() == 0;
	}
	T get(size_t index) {
		AutoLock al(this);
		return vec[index];
	}
	void remove(size_t index){
		AutoLock al(this);
		vec.remove(index);
	}
	void clear(){
		AutoLock al(this);
		vec.clear();
	}
private:
	Vector<T> vec;
};

} /* namespace yet */
